<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015-5-23
 * Time: 13:36
 */

namespace doumiaoduo\artdialog;


use yii\base\Widget;
use yii\helpers\Json;
class ArtDialog extends Widget{

    public $text='';

    public $dialogOptions=[];

    private $_rel_no;

    public function init(){
        $this->_rel_no='artdialog_'.rand(10000000,99999999);
    }

    public function run()
    {
        echo '<a rel="'.$this->_rel_no.'">'.$this->text.'</a>';
        $this->registerClientScript();
    }

    public function registerClientScript(){
        $view = $this->getView();
        ArtDialogAsset::register($view);
        $js_str="$(document).on('click','a[rel={$this->_rel_no}]',function(){ \n dialog({";
        $js_str.='min:false,max:false,lock:true,';
        foreach($this->dialogOptions as $k=>$v){
            if($k=='title'||$k=='content'||$k=='cancelVal'||$k=='left'||$k=='okVal'||$k=='top'||$k=='backdropBackground'||$k=='backdropOpacity'||$k=='padding'||$k=='skin'||$k=='id'||$k=='width'||$k=='height'){
                $js_str.="{$k}:'{$v}',\n";
            }
            else{
                $js_str.="{$k}:{$v},\n";
            }
        }
        $js_str.="}).show();});";
        $view->registerJs($js_str);
    }


}